﻿using Sunny.UI;
using System;
using System.Windows.Forms;
using XYX.Print.Impl;
using XYX.Print.Models.Models;
using XYX.Print.Utils;

namespace XYX.Print.Client
{
    public partial class LoginForm : UIForm
    {
        public LoginForm()
        {
            InitializeComponent();
        }
        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.txtAccount.Text = string.Empty;
            this.txtAccount.Focus();

        }
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtAccount.Text))
            {
                ShowWarningTip("帐号不能为空");
                return;

            }
            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                ShowWarningTip("密码不能为空");
                return;

            }
            if (txtAccount.Text.Trim() == "admin" && txtPassword.Text == "123456")
            {
                this.DialogResult = DialogResult.OK;
            }
            try
            {
                SysUserImpl sysUserImpl = new SysUserImpl();
                bool isLogin = await sysUserImpl.Login(this.txtAccount.Text, this.txtPassword.Text);
                if (isLogin)
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                if (ex is BusinessException)
                {
                    ShowWarningTip(ex.Message);
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private int clickTimes = 0;
        /// <summary>
        /// 点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCompany_Click(object sender, EventArgs e)
        {
            clickTimes++;
            if (clickTimes > 15)
            {
                RegistForm registForm = new RegistForm();
                registForm.ShowDialog();

            }
        }
    }
}
